# -*- coding:utf-8 -*-
import Pluto,struct,os
fl=Pluto.walk('mst')
for fn in fl:
    print fn.split('.')[0]
    if not os.path.exists(fn.split('.')[0]):
        os.mkdir(fn.split('.')[0])
    fp=open(fn,'rb')
    fp.seek(4)
    num=struct.unpack('i',fp.read(4))[0]
    for i in xrange(num):
        fp.seek(8+i*4)
        offset=struct.unpack('i',fp.read(4))[0]
        nextoffset=struct.unpack('i',fp.read(4))[0]
        if i==num-1:
            nextoffset=Pluto.size(fn)
        size=nextoffset-offset
        fp.seek(offset)
        dat=fp.read(size)
        tar=open(fn.split('.')[0]+os.sep+'%04d.bin'%i,'wb')
        tar.write(dat)
        tar.close()
    fp.close()